package similarity.topological;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import similarity.NetworkSimilarity;
import similarity.Similarity;
import linkprediction.Edge;
import linkprediction.Graph;
import linkprediction.Node;
import linkprediction.Ranking;

public class Jaccard extends NetworkSimilarity {

	public final static String NAME = "JC";
	public final static String FULL_NAME = "Jaccard's Coefficient (JC)";

	

	@Override
	public double getScore(Graph aGraph, Node v1, Node v2) {
		return jaccardsCoefficient(aGraph, v1, v2);
	}

	@Override
	public String getName() {
		return NAME;
	}

	@Override
	public String getFullName() {
		return FULL_NAME;
	}

	private double jaccardsCoefficient(Graph aGraph, Node v1,
			Node v2) {
		Set<Node> commons = intersection(aGraph.getNeighbors(v1),
				aGraph.getNeighbors(v2));
		Set<Node> unions = union(aGraph.getNeighbors(v1), aGraph.getNeighbors(v2));
		if (unions.size() == 0)
			return 0.0;
		return commons.size() / ((double) unions.size());
	}



	@Override
	public double getScore(Node v1, Node v2) {
		// TODO Auto-generated method stub
		return 0;
	}



}